/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

/**
 *
 * @author Gustavo
 */
public class Timer extends Thread {

    private int delay;
    private static Timer timer;
    private OnTimeoutListener listener;
    
    public static Timer getInstance(){
        if(timer == null){
            timer = new Timer();
        }
        
        return timer;
    }
    
    public void startTime(int delay) {
        this.delay = delay;
        this.start();
    }

    private Timer() {
        this.delay = Constants.getDelta();
    }

    @Override
    public void run() {
        try {
            Timer.sleep(delay);
            
            listener.onTimeoutListener();
            
        } catch (InterruptedException ex) {
        }
    }
    
    public interface OnTimeoutListener{ 
        abstract void onTimeoutListener();
    };
    
    public void setOnTimeoutListener(OnTimeoutListener l){
        this.listener = l;
    }
}
